log() {
  echo "$(date '+%Y-%m-%d %H:%M:%S') - $1"
}

MIN_VERSION=${MIN_TS_VERSION:-"4.7.4"}
MAX_VERSION=${MAX_TS_VERSION:-"5.6.0"}

log "Checking TypeScript version..."

CURRENT_TS_VERSION=$(npx tsc --version | awk '{print $2}' || { log "Failed to get TypeScript version"; exit 1; })

log "Current TypeScript version: $CURRENT_TS_VERSION"

if ! [[ $(echo "$CURRENT_TS_VERSION >= $MIN_VERSION" | bc) -eq 1 ]]; then
  log "Error: TypeScript version must be at least $MIN_VERSION"
  exit 1
fi

if ! [[ $(echo "$CURRENT_TS_VERSION < $MAX_VERSION" | bc) -eq 1 ]]; then
  log "Error: TypeScript version must be less than $MAX_VERSION"
  exit 1
fi

log "TypeScript version is within the supported range."

# 安装依赖
pnpm install
